﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeakScript
{
    class WeakFunctionDescriptor
    {
        public string Name { get; set; }
        public List<WeakVar> UtiliteVars;
        public ScriptBlock ScriptBlock;

        public WeakFunctionDescriptor(string name)
        {
            Name = name;
            UtiliteVars = new List<WeakVar>();
            ScriptBlock = new ScriptBlock();
        }

        public void PrepareUtiliteVars(List<WeakVar> args)
        {
            if (args.Count < UtiliteVars.Count) throw new ArgumentException();

            for (int i = 0; i < UtiliteVars.Count; i++)
            {
                OperationRoom.Set(UtiliteVars[i], args[i]);
            }
        }

        public void CloseUtiliteVars(List<WeakVar> args)
        {
            for (int i = 0; i < UtiliteVars.Count; i++)
            {
                OperationRoom.Set(args[i], UtiliteVars[i]);
            }
        }
    }
}
